import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   children: [
  //     {
  //       path: 'dashboard',
  //       name: 'Dashboard',
  //       component: () => import('@/views/dashboard/index'),
  //       meta: { title: '主页', icon: 'dashboard' }
  //     }
  //   ]
  // },

  {
    path: '/',
    component: Layout,
    redirect: '/schools/schools',
    name: 'Home'
  },

  {
    path: '/schools',
    component: Layout,
    redirect: '/schools/schools',
    name: 'Schools',
    alwaysShow: true,
    meta: { title: '高校管理', icon: 'el-icon-office-building' },
    children: [
      {
        path: 'schools',
        name: 'School',
        component: () => import('@/views/schools/schools'),
        meta: { title: '高校列表', icon: 'el-icon-files' }
      },
      {
        path: 'area',
        name: 'Area',
        component: () => import('@/views/area/area'),
        meta: { title: '地区列表', icon: 'el-icon-place' }
      }
    ]
  },

  {
    path: '/recruit',
    component: Layout,
    alwaysShow: true,
    redirect: '/recruit/recruit',
    name: 'Recruits',
    meta: { title: '企业招聘', icon: 'el-icon-user' },
    children: [
      {
        path: 'recruit',
        name: 'Recruit',
        component: () => import('@/views/recruit/recruit'),
        meta: { title: '招聘列表', icon: 'el-icon-receiving' }
      }
    ]
  },
  {
    path: '/project',
    component: Layout,
    redirect: '/project/project',
    name: 'Projects',
    alwaysShow: true,
    meta: { title: '签约项目管理', icon: 'el-icon-coordinate' },
    children: [
      {
        path: 'project',
        name: 'Project',
        component: () => import('@/views/project/project'),
        meta: { title: '项目列表', icon: 'el-icon-files' }
      }
    ]
  },
  {
    path: '/platform',
    component: Layout,
    alwaysShow: true,
    redirect: '/platform/platform',
    name: 'Platforms',
    meta: { title: '单页管理', icon: 'el-icon-tickets' },
    children: [
      {
        path: 'platform',
        name: 'Platform',
        component: () => import('@/views/platform/platform'),
        meta: { title: '单页列表', icon: 'el-icon-document' }
      }
    ]
  },

  {
    path: '/exchange',
    component: Layout,
    alwaysShow: true,
    redirect: '/exchange/exchange',
    name: 'Exchanges',
    meta: { title: '交流会管理', icon: 'el-icon-tickets' },
    children: [
      {
        path: 'exchange',
        name: 'Exchange',
        component: () => import('@/views/exchange/exchange'),
        meta: { title: '交流会列表', icon: 'el-icon-document' }
      }
    ]
  },
  {
    path: '/product',
    component: Layout,
    alwaysShow: true,
    redirect: '/product/product',
    name: 'Products',
    meta: { title: '产品管理', icon: 'el-icon-shopping-bag-2' },
    children: [
      {
        path: 'product',
        name: 'product',
        component: () => import('@/views/product/product'),
        meta: { title: '产品列表', icon: 'el-icon-coin' }
      }
    ]
  },

  {
    path: '/activity',
    component: Layout,
    alwaysShow: true,
    redirect: '/activity/activity',
    name: 'Activity',
    meta: { title: '活动管理', icon: 'el-icon-folder-checked' },
    children: [
      {
        path: 'activity',
        name: 'activity',
        component: () => import('@/views/activity/activity'),
        meta: { title: '活动列表', icon: 'el-icon-receiving' }
      }
    ]
  },

  {
    path: '/notice',
    component: Layout,
    alwaysShow: true,
    redirect: '/notice/notice',
    name: 'Notice',
    meta: { title: '公告管理', icon: 'el-icon-bell' },
    children: [
      {
        path: 'notice',
        name: 'notice',
        component: () => import('@/views/notice/notice'),
        meta: { title: '公告列表', icon: 'el-icon-reading' }
      }
    ]
  },
  {
    path: '/patent',
    component: Layout,
    alwaysShow: true,
    redirect: '/patent/patent',
    name: 'Patents',
    meta: { title: '专利管理', icon: 'el-icon-bell' },
    children: [
      {
        path: 'patent',
        name: 'patent',
        component: () => import('@/views/patent/patent'),
        meta: { title: '专利列表', icon: 'el-icon-reading' }
      }
    ]
  },
  {
    path: '/customcategory',
    component: Layout,
    alwaysShow: true,
    redirect: '/customcategory/customcategory',
    name: 'Customcategory',
    meta: { title: '公用模块', icon: 'el-icon-bell' },
    children: [
      {
        path: 'customcategory',
        name: 'customcategory',
        component: () => import('@/views/customcategory/customcategory'),
        meta: { title: '分类列表', icon: 'el-icon-reading' }
      },
      {
        path: 'custom',
        name: 'Custom',
        component: () => import('@/views/custom/custom'),
        meta: { title: '分类数据', icon: 'el-icon-reading' }
      },
      {
        path: 'day',
        name: 'Day',
        component: () => import('@/views/day/custom'),
        meta: { title: '日程安排', icon: 'el-icon-reading' }
      },
      {
        path: 'zpDay',
        name: 'ZpDay',
        component: () => import('@/views/dayZp/custom'),
        meta: { title: '招聘日程安排', icon: 'el-icon-reading' }
      },
      {
        path: 'ad',
        name: 'Ad',
        component: () => import('@/views/ad/custom'),
        meta: { title: '广告管理', icon: 'el-icon-reading' }
      }
    ]
  },

  {
    path: '/system',
    component: Layout,
    alwaysShow: true,
    redirect: '/system/user',
    name: 'System',
    meta: { title: '系统管理', icon: 'el-icon-setting' },
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/system/user/user'),
        meta: { title: '个人信息', icon: 'el-icon-user-solid' }
      },
      {
        path: 'password',
        name: 'password',
        component: () => import('@/views/system/user/password'),
        meta: { title: '修改密码', icon: 'el-icon-lock' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
